package com.lpc.carinfo.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.lpc.carinfo.R;
import com.lpc.carinfo.bean.CarInfoBean;
import com.lpc.carinfo.db.MyDB;
import com.lpc.carinfo.util.ToastUtils;

/**
 * Created by lipc0113 on 2017/11/19.
 */

public class AddCarActivity extends AppCompatActivity {

    private EditText et_carSeries;
    private EditText et_engineOil;
    private EditText et_jiLv;
    private EditText et_kongLv;
    private EditText et_kongTiaoLv;
    private EditText et_qilv;
    private EditText et_huosaihua;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_car);

        initView();
        initData();
    }

    private void initView() {

        et_carSeries = findViewById(R.id.et_carSeries);
        et_engineOil = findViewById(R.id.et_engineOil);
        et_jiLv = findViewById(R.id.et_jiLv);
        et_kongLv = findViewById(R.id.et_kongLv);
        et_kongTiaoLv = findViewById(R.id.et_kongTiaoLv);
        et_qilv = findViewById(R.id.et_qilv);
        et_huosaihua = findViewById(R.id.et_huosaihua);
    }

    private void initData() {
        
    }

    public void add(View view) {

        String carSeries = et_carSeries.getText().toString();
        String engineOil = et_engineOil.getText().toString();
        String jiLv = et_jiLv.getText().toString();
        String kongLv = et_kongLv.getText().toString();
        String kongTiaoLv = et_kongTiaoLv.getText().toString();
        String qilv = et_qilv.getText().toString();
        String huosaihua = et_huosaihua.getText().toString();

        CarInfoBean bean = new CarInfoBean();
        bean.setCarSeries(carSeries);
        bean.setEngineOil(engineOil);
        bean.setJiLv(jiLv);
        bean.setKongLv(kongLv);
        bean.setKongTiaoLv(kongTiaoLv);
        bean.setQilv(qilv);
        bean.setHuosaihua(huosaihua);

        if(TextUtils.isEmpty(bean.getCarSeries())){

            ToastUtils.showShortToast("车系不能为空");
            return;
        }

        if(MyDB.getInstace().addOrUpdate(bean)){
            ToastUtils.showShortToast("添加成功");
            et_carSeries.setText("");
            et_engineOil.setText("");
            et_jiLv.setText("");
            et_kongLv.setText("");
            et_kongTiaoLv.setText("");
            et_qilv.setText("");
            et_huosaihua.setText("");
        }else{
            ToastUtils.showShortToast("添加失败");
        }
    }
}
